//package cn.edu.xmu.restfuldemo.service;
//import cn.edu.xmu.restfuldemo.model.BO.Log;
//import cn.edu.xmu.restfuldemo.util.JacksonUtil;
//import org.apache.rocketmq.client.producer.SendCallback;
//import org.apache.rocketmq.client.producer.SendResult;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Service;
//
//
//import javax.annotation.Resource;
//import java.time.LocalDateTime;
//
//
///**
// * @author Ming Qiu
// * @date Created in 2020/11/7 22:53
// **/
//@Service
//public class RocketMQService {
//
//    private static final Logger logger = LoggerFactory.getLogger(RocketMQService.class);
//
//    @Resource
//    private RocketMQTemplate rocketMQTemplate;
//
//
//    @Value("${rocketmqdemo.order-pay-topic.delay-level}")
//    private int delayLevel;
//
//    @Value("${rocketmqdemo.order-pay-topic.timeout}")
//    private long timeout;
//
//    public void sendLogMessage(Log log){
//
//        String json = JacksonUtil.toJson(log);
//        Message message = MessageBuilder.withPayload(json).build();
//        logger.info("sendLogMessage: message = " + message);
//        rocketMQTemplate.sendOneWay("log-topic:1", message);
//    }
//
//    public void sendOrderPayMessage(Long orderId){
//        logger.info("sendOrderPayMessage: send message orderId = "+orderId+" delay ="+delayLevel+" time =" +LocalDateTime.now());
//        rocketMQTemplate.asyncSend("order-pay-topic", MessageBuilder.withPayload(orderId.toString()).build(), new SendCallback() {
//            @Override
//            public void onSuccess(SendResult sendResult) {
//                logger.info("sendOrderPayMessage: onSuccess result = "+ sendResult+" time ="+LocalDateTime.now());
//            }
//
//            @Override
//            public void onException(Throwable throwable) {
//                logger.info("sendOrderPayMessage: onException e = "+ throwable.getMessage()+" time ="+LocalDateTime.now());
//            }
//        }, timeout * 1000, delayLevel);
//    }
//}
